unit uFotoVenda;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, StdCtrls, ExtCtrls, DBCtrls;// JpgImg;

type
  TfFotoVenda = class(TForm)
    DBNavigator1: TDBNavigator;
    Button3: TButton;
    Button2: TButton;
    Button1: TButton;
    Button4: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    DataSource1: TDataSource;
    Image1: TImage;
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fFotoVenda: TfFotoVenda;

implementation

uses UDM, uPesquisa_Locacao, uPrincipal, uPesquisa_Vendas;

{$R *.dfm}

procedure TfFotoVenda.Button3Click(Sender: TObject);
begin
  if dm.cds_foto.Active then
    dm.cds_foto.Close;
    dm.cds_foto.Params[0].AsString :=
    IntTostr(dm.cds_imo_vendaCOD_IMOVENDA.AsInteger) + '-V';
    dm.cds_foto.Open;
    if dm.cds_foto.IsEmpty then
    begin
     dm.cds_foto.Append;
     dm.cds_fotoCOD_IMOVEL.AsString :=
       IntTostr(dm.cds_imo_vendaCOD_IMOVENDA.AsInteger) + '-V';
     dm.cds_fotoNOME_FOTO.AsString :=
       OpenDialog1.FileName;
     dm.cds_foto.ApplyUpdates(0);
    end
    else
    begin
      if dm.cds_foto.Locate('NOME_FOTO',OpenDialog1.FileName,[loPartialKey])then
      begin
        dm.cds_foto.Edit;
        dm.cds_fotoCOD_IMOVEL.AsString :=
        IntTostr(dm.cds_imo_vendaCOD_IMOVENDA.AsInteger) + '-V';
        dm.cds_fotoNOME_FOTO.AsString :=
        OpenDialog1.FileName;
        dm.cds_foto.ApplyUpdates(0);
      end
      else
      begin
        dm.cds_foto.Append;
        dm.cds_fotoCOD_IMOVEL.AsString :=
        IntTostr(dm.cds_imo_vendaCOD_IMOVENDA.AsInteger) + '-V';
        dm.cds_fotoNOME_FOTO.AsString :=
        OpenDialog1.FileName;
        dm.cds_foto.ApplyUpdates(0);
      end;
    end;
end;

procedure TfFotoVenda.Button2Click(Sender: TObject);
begin
  Image1.Picture.Bitmap.Assign(nil);
  if dm.cds_foto.Active then
  begin
     dm.cds_foto.Delete;
     dm.cds_foto.ApplyUpdates(0);
  end;
end;

procedure TfFotoVenda.Button1Click(Sender: TObject);
begin
  OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName);
  if OpenDialog1.Execute
    then Image1.Picture.LoadFromFile(OpenDialog1.FileName);
end;

procedure TfFotoVenda.Button4Click(Sender: TObject);
begin
close;
end;

procedure TfFotoVenda.DBNavigator1Click(Sender: TObject;
  Button: TNavigateBtn);
begin
  Image1.Picture.LoadFromFile(dm.cds_fotoNOME_FOTO.AsString);
end;

procedure TfFotoVenda.FormCreate(Sender: TObject);
begin
  if dm.cds_foto.Active then
    dm.cds_foto.Close;
  if dm.cds_imo_venda.Active then
  begin
    dm.cds_foto.Params[0].Clear;
    dm.cds_foto.Params[0].AsString :=
    IntTostr(dm.cds_imo_vendaCOD_IMOVENDA.AsInteger) + '-V';
  end
  else
    dm.cds_foto.Params[0].AsString :=
    IntTostr(fPesquisa_Vendas.scdsCp_proc1COD_IMOVENDA.AsInteger) + '-V';
    dm.cds_foto.Open;
  if not dm.cds_foto.IsEmpty then
   Image1.Picture.LoadFromFile(dm.cds_fotoNOME_FOTO.AsString);
end;

end.
